home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.04 Apr 91 / Code Optimizing / Sources / Mxmpy.FPU.a < prev    next >
Encoding:
Text File  |  1990-04-28  |  5.4 KB  |  147 lines  |  [TEXT/MPS ]

  1.       MACHINE MC68020
  2.       MC68881
  3. ;-------------------------------------------------
  4. Mxmpy       PROC        EXPORT
  5. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  6. ;  Performs the matrix multiplication C = A * B.
  7. ;
  8. ;  Calling sequence (FORTRAN):
  9. ;      CALL MXMPY (A, B, C, L, M, N)
  10. ;
  11. ;  where
  12. ;      A is an array with L rows and M columns
  13. ;      B is an array with M rows and N columns
  14. ;      C is an array with L rows and N columns
  15. ;      L, M, and N are INTEGERs.
  16. ;
  17. ;  NOTE:  All arrays must be completely filled,
  18. ;  with no gaps. Do not try to pass part of an
  19. ;  array unless it forms a contiguous block of
  20. ;  memory locations.
  21. ;
  22. ;  April 1990
  23. ;  Jon Bell, Dept. of Physics & Computer Science
  24. ;  Presbyterian College, Clinton SC 29325 
  25. ;
  26. ;  Written for MPW Assembler, v3.0.
  27. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  28. ;  Locations of arguments to the subroutine,
  29. ;  relative to the address stored in register A6.
  30. a           EQU     28      ; addr. of a
  31. b           EQU     24      ; addr. of b
  32. c           EQU     20      ; addr. of c
  33. l           EQU     16      ; addr. of # rows in a
  34. m           EQU     12      ; addr. of # cols in a
  35. n           EQU     8       ; addr. of # cols in b
  36. ;  Locations of local variables, relative to the
  37. ;  address stored in register A6.
  38. termCount   EQU  -4  ; initial value of term index
  39. rowCount    EQU  -8  ; initial value of col. index
  40. aColSize    EQU -12  ; # of bytes per column of a
  41. bColSize    EQU -16  ; # of bytes per column of b
  42. ;  Other constants.
  43. ParamSize   EQU  24  ; # of bytes of parameters
  44. LocalSize   EQU -16  ; # of bytes of local var's
  45. zero        EQU $0F  ; 68882 code for constant 0
  46. ;  Register usage.
  47. aPtr        EQU  A2  ; pointer into a
  48. bPtr        EQU  A3  ; pointer into b
  49. cPtr        EQU  A4  ; pointer into c
  50. rowIndex    EQU  D3  ; row-loop index
  51. colIndex    EQU  D4  ; column-loop index
  52. termIndex   EQU  D5  ; term-loop index
  53. aRowBase    EQU  D6  ; start of current row in a
  54. bColBase    EQU  D7  ; start of current col. in b
  55. term        EQU  FP0 ; one term for an elem. of c
  56. sum         EQU  FP1 ; sum for an element of c
  57. ;- - - - - - - - - - - - - - - - - - - - - - - - -
  58. ;  Set up the stack frame, and save registers on
  59. ;  the stack.
  60.       LINK        A6, #LocalSize
  61.       MOVEM.L     A2-A4/D3-D7, -(SP)
  62. ;  Calculate and save the length of 
  63. ;  one column of a.
  64.       MOVE.L      l(A6), A0
  65.       MOVE.L      (A0), D0      ; # of rows
  66.       MULU        #12, D0       ; bytes per column
  67.       MOVE.L      D0, aColSize(A6)
  68. ;  Calculate and save the length of 
  69. ;  one column of b.
  70.       MOVE.L      m(A6), A0
  71.       MOVE.L      (A0), D0      ; # of rows
  72.       MULU        #12, D0       ; bytes per column
  73.       MOVE.L      D0, bColSize(A6)
  74. ;  Save the initial value of the term index.
  75.       MOVE.L      m(A6), A0
  76.       MOVE.L      (A0), termCount(A6)
  77. ;  Save the initial value of the row index.
  78.       MOVE.L      l(A6), A0
  79.       MOVE.L      (A0), rowCount(A6)
  80. ;  Initialize the column index.
  81.       MOVE.L      n(A6), A0
  82.       MOVE.L      (A0), colIndex
  83. ;  Initialize the base address of the current
  84. ;  column in b to the start of b.
  85.       MOVE.L      b(A6), bColBase
  86. ;  Initialize the pointer into c.
  87.       MOVE.L      c(A6), cPtr
  88. BeginColLoop      ;  Cycle over the columns of c.
  89.             SUBQ.L      #1, colIndex
  90.             BMI.S       EndColLoop
  91.       ;  Initialize the row index.
  92.             MOVE.L      rowCount(A6), rowIndex
  93.       ;  Initialize the base address of the
  94.       ;  current row in a to the start of a.
  95.             MOVE.L      a(A6), aRowBase
  96. BeginRowLoop      ; Cycle over the rows of c.
  97.                   SUBQ.L      #1, rowIndex
  98.                   BMI.S       EndRowLoop
  99.             ;  Initialize the a and b pointers 
  100.             ;  for the next sum of terms.
  101.                   MOVE.L      aRowBase, aPtr
  102.                   MOVE.L      bColBase, bPtr
  103.             ;  Initialize the sum.
  104.                   FMOVECR.X   #zero, sum
  105.             ;  Initialize the term index.
  106.                   MOVE.L  termCount(A6), termIndex
  107. BeginTermLoop     ; Cycle over the terms 
  108.                   ; in the sum.
  109.                         SUBQ.L      #1, termIndex
  110.                         BMI.S       EndTermLoop
  111.                   ;  Multiply the current element
  112.                   ;  of b by the current element
  113.                   ;  of a, and advance to the
  114.                   ;  next element in the current
  115.                   ;  column of b.
  116.                         FMOVE.X     (bPtr)+, term
  117.                         FMUL.X      (aPtr), term
  118.                   ;  Add the new term to the sum.
  119.                         FADD.X      term, sum
  120.                   ;  Advance to the next element
  121.                   ;  in the current row of a.
  122.                         ADDA.L  aColSize(A6), aPtr
  123.                         BRA.S       BeginTermLoop
  124. EndTermLoop
  125.             ;  Move the sum into the current
  126.             ;  element of c, and advance to the
  127.             ;  next row in the current 
  128.             ;  column of c.
  129.                   FMOVE.X     sum, (cPtr)+
  130.             ;  Advance to the next row in the
  131.             ;  current column of a.
  132.                   ADD.L       #12, aRowBase
  133.                   BRA.S       BeginRowLoop
  134. EndRowLoop
  135.       ;  Advance to next column in b.
  136.             ADD.L       bColSize(A6), bColBase
  137.             BRA.S       BeginColLoop
  138. EndColLoop
  139. ;  All done.  Restore the saved registers, 
  140. ;  clean up the stack and return.
  141.       MOVEM.L     (SP)+, A2-A4/D3-D7
  142.       UNLK        A6
  143.       RTD         #ParamSize
  144.       DC.B        'MXMPY   ' ; label for debugger
  145.       ENDPROC
  146.       END
  147.